<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
/**
 * @var Mage_Page_Block_Html_Header $this
 */
 Mage::getBaseUrl();
?>
<header class="header-container">
    <section class="header">
        <article class="header-top">
			<?php echo $this->getChildHtml('topLinks') ?>
		</article>
		<article class="header-center">
		<section class="logo-home">
			<a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a>      
		</section>
		<!--end logo-->      
		<section class="header-giveus">            
			<figure>
				<img src="<?php echo $this->getSkinUrl('images/phone.png')?>">
			</figure> 
			<p>Give us a ring!<span>6285 0320</span></p>
		</section>
    </article>       
	<?php echo $this->getChildHtml('topContainer'); ?>
    </section>
	
	<section class="header-background"></section>
	<div class="no-display timeout">
		<div id="loginPopup" class="lightbox">
			<input type="hidden" id="isLoggedIn" value="<?php if($this->helper('customer')->isLoggedIn()) echo '1'; else echo '0';?>"/>
			<header>
				<p>
					Start Shopping to
					<span>
						Save!
					</span>
				</p>
				<div></div>
			</header>
			
			<article class="popup-content">
				<div class="again"><span>Oops! You've been timed out. Please log in again.</span></div>
				<a href="#" class="modalClose">close x</a>
				<p>
					Log in
				</p>
				<form method="POST" id="loginForm">
					<ul class="form-list">
						<li>
							<div class="input-box email">								
								<input type="text" name="login[username]" id="email" placeholder="email address" class="input-text validate-user-confirm required-entry validate-email" title="Email Address">
							</div>
						</li>
						<li>
							<div class="input-box pass">								
								<input type="password" name="login[password]" autocomplete="off" class="input-text required-entry validate-user-confirm validate-password" placeholder="password" id="pass" title="Password">
							</div>
							<a target="_blank" href="<?php echo $this->getUrl('customer/account/forgotpassword')?>" class="forgot">Forgot Password?</a>
						</li>
					</ul>
					<div class="buttons-set">
						<button type="submit" class="button" title="Login" name="send" id="loginBtn" onClick="logInOkBaby()">
							<span>
								<span>
									login
								</span>
							</span>
						</button>
						<span class="please-wait" id="login-please-wait" style="display:none;">
							<img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Please wait...') ?>" title="<?php echo $this->__('Please wait...') ?>" class="v-middle" /> <?php echo $this->__('') ?>
						</span>
						<p id="popupError"></p>
					</div>
					<a class="popup-register-link" target="_blank" href="<?php echo $this->getUrl('customer/account/create')?>">register</a>
				</form>
				<figure class="hugo">
					<img src="<?php echo $this->getSkinUrl('images/hugo.png')?>">
				</figure>
			</article>
		</div>		
	</div>
	
	<script type="text/javascript">
		jQuery(function(){
			// jQuery('input[placeholder]').placeholder();	
		});
		
		function correctProtocol(url){
			var currentProtocol = location.protocol;
			
			if(url.indexOf(currentProtocol) == -1){
				if(currentProtocol == 'http:'){
					return url.replace('https','http');
				}else{
					return url.replace('http','https');
				}
			}
			return url;
		}
	
		function showLoginPopup() {
			if(isLoggedIn())
				return;
			jQuery('#loginPopup').modal({
				closeClass : 'modalClose',
				opacity: 60,
				'escClose': true,
				'overlayClose': true
			});
		}	
		
		function logInOkBaby() {
			jQuery('#loginForm').bind('submit', function(event) {
				event.preventDefault();
			});
			jQuery('#popupError').fadeOut();
			var validator = new Validation('loginForm');
			if (validator.validate()) {
				jQuery('#loginForm .buttons-set').addClass('disabled');
				jQuery('#login-please-wait').show();
				jQuery.ajax({
					type : 'POST',
					url: correctProtocol('<?php echo $this->helper('gtgobbler/customer ')->getAjaxLogInUrl()?>'),
					data: jQuery('#loginForm').serialize(),
					dataType : 'JSON',
					success: function(data){
						jQuery('#login-please-wait').hide();
						jQuery('#loginForm .buttons-set').removeClass('disabled');						
						if(data.error == true){
							jQuery('#popupError').html(data.msg).fadeIn();				
							return;
						}else{							
							jQuery.modal.close();
							if(data.redirect)
							window.location = data.redirect;
						}
					}
				});
			}
		}
		
		function isLoggedIn(){
			return jQuery('#isLoggedIn').val() == 1;
		}
	</script>
</header>